package y_2025.m03.d17.t02;

public class Stock {
    private String code;
    private String name;
    private double previousClosingPrice;
    private double currentPrice;

    public Stock(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public void setPreviousClosingPrice(double previousClosingPrice) {
        this.previousClosingPrice = previousClosingPrice;
    }

    public void setCurrentPrice(double currentPrice) {
        this.currentPrice = currentPrice;
    }

    public double getChangePercent() {
        return ((currentPrice - previousClosingPrice) / previousClosingPrice) * 100;
    }

    public static void main(String[] args) {
        Stock stock = new Stock("AAPL", "Apple Inc.");
        stock.setPreviousClosingPrice(150.0);
        stock.setCurrentPrice(155.0);
        System.out.println("价格变化百分比: " + stock.getChangePercent() + "%");
    }
}